<?php
/**
 * User:于小涛
 * Date:2020/2/16
 * Time:17:36
 */

use think\response\Json;

/**
 * 后台统一返回处理函数
 * User:于小涛
 * Date:2020/2/16
 * Time:17:41
 * @param array $arr_data
 * @param string $str_code_name
 * @param string $str_msg
 * @param int $int_http_code
 * @param array $arr_other_data
 * @return Json
 */
function output_data($arr_data=array(),$str_code_name='success',$str_msg='',$int_http_code=200,$arr_other_data=array()){
    $str_code_name = $str_code_name??'success';
    $arr_code=config("statuscode.".$str_code_name);
    $arr_data_re=array(
        'ret'=>$arr_code['code'],
        'reason'=>empty($str_msg)?$arr_code['msg']:$str_msg,
        'data'=>$arr_data,
    );
    if(env('APP_DEBUG')) {
        $arr_log_channel = config('log.channels');
        $arr_other_data['log'] = [];
        foreach ($arr_log_channel as $str_key => $arr_channel_item) {
            $arr_other_data['log'] = array_merge($arr_other_data['log'], \think\facade\Log::getLog($str_key));
        }
    }
    $arr_data_re=array_merge($arr_other_data,$arr_data_re);
    return json($arr_data_re,$int_http_code);
}